/**
 * TabVD is a Virtual Desktop Client/Server designed specifically for connecting
 * from Tablet like devices.
 *
 * Copyright (C) 2011 Subhabrata Ghosh
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * AbstractConfiguration.h
 *
 *  Created on: May 24, 2011
 *      Author: subhagho
 */

#ifndef ABSTRACTCONFIGURATION_H_
#define ABSTRACTCONFIGURATION_H_
#include <string>
#include <stdlib.h>

#include <boost/unordered_map.hpp>

#include "CommonDefs.H"
#include "DateTime.h"

#include "ConfigurationDefs.H"

namespace tabvd {

    typedef boost::unordered_map<std::string, ConfigValue> Config;
    typedef boost::unordered_map<std::string, ConfigElement> ConfigDef;

	/* --------------------------------------------------------------------------*/
	/**
	 * @Synopsis  
	 */
	/* ----------------------------------------------------------------------------*/
	class AbstractConfiguration {
		protected:
			/*
			 * Variable Declarations
			 */
			EInstanceState state;
			Config* config;
			ConfigDef* cdefs;
            
			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param deffile
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			bool loaddefs(const std::string& deffile);
			
			ConfigElement* parsedef(char* buffer);

			/*
			 * Method Declarations
			 */
			AbstractConfiguration();

		public:
			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			const std::string get(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			int getInt(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			long getLong(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			double getDouble(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			DateTime* getDatetime(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 * @Param format
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			DateTime* getDatetime(const std::string key, std::string format);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 * @Param value
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			bool set(const std::string key, const std::string value);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			bool remove(const std::string key);

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param key
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			bool containsKey(const std::string key);

			/*
			 * Virtual functions.
			 */
			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param filename
			 */
			/* ----------------------------------------------------------------------------*/
			virtual void init(std::string filename) = 0;

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 */
			/* ----------------------------------------------------------------------------*/
			virtual void save() = 0;

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Param filename
			 */
			/* ----------------------------------------------------------------------------*/
			virtual void save(const std::string filename) = 0;

			/* --------------------------------------------------------------------------*/
			/**
			 * @Synopsis  
			 *
			 * @Returns   
			 */
			/* ----------------------------------------------------------------------------*/
			EInstanceState getState();

			virtual ~AbstractConfiguration();
	};

}

#endif /* ABSTRACTCONFIGURATION_H_ */

